package com.enzoism.spring.controller;

import com.enzoism.spring.bean.UserModel;
import com.enzoism.spring.common.http.Result;
import com.netflix.appinfo.InstanceInfo;
import com.netflix.discovery.DiscoveryClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import com.wenrui.springboot.util.common.http.ResultGenerator;

import java.util.List;

/**
 * @program: springcloud-test-2
 * @description: 电影接口
 * @author: zhifeng
 * @create: 2020-12-07 10:51
 */
@RestController
@RequestMapping("movie1")
public class MovieController {

    @Autowired
    private RestTemplate restTemplate;
    @Autowired
    private DiscoveryClient discoveryClient;

    @RequestMapping("/discovery/userList")
    public Result getUserListByDiscovery() {
        List<InstanceInfo> instancesByIdList = discoveryClient.getInstancesById("SPRINGCLOUD-PROVIDER-USER");
        return ResultGenerator.genSuccessResult(instancesByIdList);
    }

    @RequestMapping("/template/user/{id}")
    public Result getUserListByTemplate(@PathVariable String id) {
        UserModel userModel = restTemplate.getForObject("http://127.0.0.1:7101/user/user/" + id, UserModel.class);
        return ResultGenerator.genSuccessResult(userModel);
    }

}
